﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using YuanCodeStudio.Const;

/*
 * 类名：YuanCodeStudioSetup
 * 描述：
 * 创 建 者：十一 
 * 创建时间：2024/6/26 0:06:09 
 */
namespace YuanCodeStudio
{
    public static class YuanCodeStudioSetup
    {
        public static void AddYuanCodeStudioSetup(this IServiceCollection services)
        {
            // TODO: dll混淆，反编译测试
            //if (Debugger.IsAttached || Debugger.IsLogging()) Environment.Exit(1);  // 禁止使用调试器
            services.AddSignalR();
            services.AddSingleton(sp =>
            {
                var handler = new HttpClientHandler
                {
                    UseDefaultCredentials = false
                };
                return new HttpClient(handler);
            });
            services.AddHostedService<YuanCodeStudioHttp>();
        }

        public static void UseYuanCodeStudioSetup(this IApplicationBuilder app)
        {
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapHub<YuanCodeStudioHub>(StaticConst.MAPHUB_PATTERN);
            });
        }
    }
}
